using System;
using BoxBinary.AspectCache.Core.ErrorLogging;

namespace BoxBinary.AspectCache.Core.Logging
{
    /// <summary>
    /// Provides static methods designed to help dealing with errors in an application
    /// </summary>
    public class ErrorHelper
    {
        /// <summary>
        /// Logs an error using the Selected Log Provider specified in the Configuration
        /// </summary>
        /// <param name="ex"></param>
        public static void LogError(Exception ex)
        {
            LogError(ex, true);
        }

        /// <summary>
        /// Logs an error using the Selected Log Provider specified in the Configuration
        /// </summary>
        /// <param name="ex"></param>
        /// <param name="hideError"></param>
        public static void LogError(Exception ex, bool hideError)
        {
            ILogProvider log = ErrorLogProvider.Current.DefaultErrorLogger;
            log.StartNewLog(ex, hideError);
            log.SaveLog();
        }

        public static void LogMessage(string title, string message)
        {
            ILogProvider log = ErrorLogProvider.Current.DefaultErrorLogger;
            var ex = new Exception(string.Format("Log: {0} [{1}]", title, Environment.UserName));
            log.StartNewLog(ex, true);
            log.Body =
                string.Format(
                                 "<h1>{0}</h1><p>{1}</p><h4>Metadata</h4><ul><li>Current User: {2}</li><li>Working Set: {3}</li><li>OS: {4}</li></ul>",
                                 title, message, Environment.UserName, Environment.WorkingSet,
                                 Environment.OSVersion.VersionString);
            log.SaveLog();
        }
    }
}